/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package intelligenttm.ITMCarto;

import intelligenttm.InPutDlg.AddFenQuDlgController;
import intelligenttm.InPutDlg.AddNewFenQuTypeDlgController;
import intelligenttm.InPutDlg.AddNewTypeDlgController;
import intelligenttm.SourceFile.CartoType;
import intelligenttm.SourceFile.FenQuCartoType;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.image.Image;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;

/**
 * FXML Controller class
 *
 * @author 望舒凌霄
 */
public class SPartitionSatisticalGraphController implements Initializable {
    @FXML
    private AnchorPane RootPane;
    @FXML
    private Button BtnCancel;
    @FXML
    private Button BtnLast;
    @FXML
    private Button BtnNext;
    @FXML
    private TableView<AddFenQuDlgController> FenQuTypeTableView;
    @FXML
    private TableColumn<AddFenQuDlgController, String> FenQuTypeInt;
    @FXML
    private TableColumn<AddFenQuDlgController, String> FenQuType;
    @FXML
    private TableColumn<AddFenQuDlgController, Image> FenQuTypeSample;
    @FXML
    private Button BtnDeleteType;
    @FXML
    private Button BtnAddType;
    
    private List<AddFenQuDlgController> FenQuCartoTypeList=new ArrayList<>();
    private ObservableList<AddFenQuDlgController> FenQuCartoTypeItemList =  FXCollections.observableArrayList();
    private int WhichBtn=0;
    private List<BaseData> BD=null;
    /**
     * Initializes the controller class.
     */
    @Override
    public void initialize(URL url, ResourceBundle rb) {
        FenQuCartoTypeList.clear();
        FenQuCartoTypeItemList.clear();
        SetTableColumn();// TODO
    }    
    public void setBaseData(List<BaseData> tBD){
        BD=tBD;
    }
//    public void SetFenQuCartoTypeList(List<AddFenQuDlgController> tCartoTypeList ){
//        FenQuCartoTypeList=tCartoTypeList;
//        FenQuCartoTypeItemList.clear();
//        FenQuCartoTypeItemList.addAll(FenQuCartoTypeList);
//        FenQuTypeTableView.setItems(FenQuCartoTypeItemList);
//    }
    @FXML
    private void HandleBtnCancel(ActionEvent event) {
        WhichBtn=0;
        RootPane.getScene().getWindow().hide();
    }

    @FXML
    private void HandleBtnLast(ActionEvent event) {
        WhichBtn=-1;
        RootPane.getScene().getWindow().hide();
    }

    @FXML
    private void HandleBtnNext(ActionEvent event) {
        FenQuCartoTypeList.clear();
        FenQuCartoTypeItemList.stream().forEach((CartoTypeItemList1) -> {
            FenQuCartoTypeList.add(CartoTypeItemList1);
        });
        WhichBtn=1;
        RootPane.getScene().getWindow().hide();
    }

    @FXML
    private void HandleBtnDeleteType(ActionEvent event) {
        int i=FenQuTypeTableView.getSelectionModel().getFocusedIndex();
        if(i>=0){
            FenQuCartoTypeItemList.remove(i);
            FenQuTypeTableView.setItems(FenQuCartoTypeItemList);
        }
    }

    @FXML
    private void HandleBtnAddType(ActionEvent event) throws IOException {
        FXMLLoader fXMLLoader1 = new FXMLLoader(getClass().getResource("/intelligenttm/InPutDlg/AddFenQuDlg.fxml"));
        Parent root1=fXMLLoader1.load();
        AddFenQuDlgController MyController;
        MyController=fXMLLoader1.getController();
//        MyController.SetBaseData(tBaseData);
        MyController.SetBaseData(BD);
        Scene scene1 = new Scene(root1);
        Stage stage1 = new Stage();
        stage1.setTitle("类型选择");
        stage1.setScene(scene1);
        stage1.showAndWait();
        MyController.setCountNum(""+FenQuCartoTypeItemList.size());
        FenQuCartoTypeItemList.add(MyController);
        FenQuTypeTableView.setItems(FenQuCartoTypeItemList);
    }
    
     private void SetTableColumn(){
        FenQuTypeInt.setCellValueFactory(new PropertyValueFactory<>("CountNum"));
        FenQuType.setCellValueFactory(new PropertyValueFactory<>("FenQuType"));
        FenQuTypeSample.setCellValueFactory(new PropertyValueFactory<>("ShowSample"));
    }

    public List<AddFenQuDlgController> getFenQuCartoTypeList() {
        return FenQuCartoTypeList;
    }

    public void setFenQuCartoTypeList(List<AddFenQuDlgController> FenQuCartoTypeList) {
        this.FenQuCartoTypeList = FenQuCartoTypeList;
    }

    public int getWhichBtn() {
        return WhichBtn;
    }

    public void setWhichBtn(int WhichBtn) {
        this.WhichBtn = WhichBtn;
    }
    
}
